<?php
/**
 * @copyright meila.com
 * @author shaopu@
 * @name 
 * @param 
 *         $xxx = 作用
 * @static 
 *         XXX = 作用
 * 
 * 
 */
$dir = dirname(dirname(__FILE__));
include($dir.'/__queue_global.php');

class ml_mq_add_feed extends MqClass{
    const QUEUE_NAME = ML_QUEUENAME_ADD_FEED;
    private $oPublicFeed ;
    private $oPicFeed ;
    private $oUserFeed;
    private $pic_id;
    private $arrFeedInfo;    //    pic 和 pub feedinfo 
    public function __construct($queue)
    {
        $this->oPicFeed = new ml_model_dbPicFeed();
        $this->oPublicFeed = new ml_model_dbPublicFeed();
        $this->oUserFeed = new ml_model_dbUserfeed();
        
        parent::__construct($queue);
    }

    public function run_job(){
        //接收的数据
        $arr = $this->src_data;
        
        //    判断类型是 转发的 或表态
        if($arr['type'] == 'repost' || $arr['type'] == 'atti') {
            //$this->_add_userFeed($arr);
        }
        
        $re = $this->oUserFeed->getUserfeedByRid($arr['feed_rid']);
        
        $data = $this->oUserFeed->get_data();
        if( empty($data['content_rid'])) {
            $data['content_rid'] = $data['feed_info']['rid'];
        }
        
        $data['quote_info'] = array(
                'uid'=>$arr['uid'],
                'content'=>$arr['comment'],
                'nick'=>$arr['nick']
        );
        
        switch ($data['type'])
        {        
            case ML_FEED_TYPE_PUB_DOTEY:
            case ML_FEED_TYPE_PUB_PIC:
            case ML_FEED_TYPE_REPOST_PIC:
            case ML_FEED_TYPE_REPOST_COLLECTION:
            case ML_FEED_TYPE_ATTITUDE:       //喜欢进入picfeed
                $this->_add_picFeed($data);
                
            case ML_FEED_TYPE_PUB_SHORT:
            case ML_FEED_TYPE_MOD_DEC:
            case ML_FEED_TYPE_REPOST_SHORT:
                    
            case ML_FEED_TYPE_MOD_TAG:
                $this->_add_publicFeed($data);
                break;
            default:
                break;
        }
        
        return true;
    }

    private function _add_picFeed($data){
        
        $arr = array(
                    'content_rid' => $data['content_rid'],
                    'userfeed_rid' => $data['rid'],                    
                    'uid' => $data['uid'],
                    'type' => $data['type'],     
                    'content' => $data['content'],     
                    'pic_id' => $data['pic_id'],
                    'from' => $data['from'],    
                    'ctime' => $data['ctime'],     
                    'cip' => $data['cip'],
                    'feed_info' => $data['feed_info'],
        );
        
        //    $arr['feed_info']['quote_info'] = $data['quote_info'];
        
        if($data['type'] == ML_FEED_TYPE_PUB_DOTEY || ML_FEED_TYPE_PUB_PIC == $data['type']) {
            $arr['isown'] = 1;
            //$arr['feed_info'] = $data['feed_info'];
        }else {
            $arr['isown'] = 0;
            //$arr['feed_info'] = $this->arrFeedInfo;
        }        

        $this->oPicFeed->add_feed($arr);
        
        
    }
    
    private function _add_publicFeed($data){
        
            $arr = array(
                    'content_rid' => $data['content_rid'],
                    'userfeed_rid' => $data['rid'],
                    'uid' => $data['uid'],
                    'type' => $data['type'],     
                    'content' => $data['content'],     
                    'pic_id' => $data['pic_id'], 
                    'feed_info' => $data['feed_info'],     
                    'from' => $data['from'],    
                    'ctime' => $data['ctime'],     
                    'cip' => $data['cip'],
        );    
        
        $this->oPublicFeed->add_feed($arr);
    }
    
   
    private function _getFeedInfo($arr) {
                
        $oContent = new ml_model_dbContent();
        $oContent->get_by_rid($arr['content_rid']);
        $content = $oContent->get_data();
        
        $this->arrFeedInfo = array(
            'gd_title'=>$content['gd_title'],
            'gd_price'=>$content['gd_price'],
            'gd_url'=>$content['gd_info']['gd_url'],
            'gd_pic'=>$content['gd_info']['gd_pic'],
            'uid'=>$content['uid'],
        );
        
        if($arr['type'] == 'repost') {
            $this->arrFeedInfo['col_name'] = $arr['col_name'];
            $this->arrFeedInfo['col_id'] = $arr['col_id'];
        }
        
        //    表态?
    }
 
    
 

}





ml_run_queue_check(ml_mq_add_feed::QUEUE_NAME);

$conf_array = ml_factory::load_standard_conf('redis');
$conf_array = $conf_array['meila_queue'];
$xblog_obj = new ml_mq_add_feed(new RsQueue(ml_mq_add_feed::QUEUE_NAME , $conf_array));
$argv[1]   = __FILE__;
$xblog_obj->setArgv($argv[1]);
$xblog_obj->execute();
?>